<template>
  <div>
    <!-- 头部搜索框start -->
    <div class="hot-search-header">
      <div class="hot-search-back" @click="goback"></div>
      <div class="hot-search-block">
        <van-search
          v-model="searchKey"
          show-action
          placeholder="请输入搜索关键词"
          @search="onSearch"
        >
          <template #action>
            <div @click="onSearch">搜索</div>
          </template>
        </van-search>
      </div>
    </div>
    <!-- 头部搜索框end -->
    <!-- 热门搜索start -->
    <div class="hot-search-key">
      <dl>
        <dt>热门搜索</dt>
        <dd>
          <span
            v-for="(item, index) in hotSearchList"
            :key="index"
            :class="{ 'super-hot': item.isMark }"
          >
            {{ item.searchCode }}
          </span>
        </dd>
      </dl>
    </div>
    <!-- 热门搜索end -->
    <!-- 历史记录start -->
    <div class="hot-search-history">
      <dl>
        <dt>历史记录</dt>
        <dd>
          <span v-for="(item, index) in searchHistory" :key="index">
            {{ item.searchCode }}
          </span>
        </dd>
      </dl>
    </div>
    <!-- 历史记录end -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      searchKey: '',
      searchHistory: [
        {
          id: 1,
          searchCode: '电动牙刷',
          isMark: false,
        },
        {
          id: 2,
          searchCode: '汾酒超品日',
          isMark: true,
        },
        {
          id: 3,
          searchCode: '九阳超品预定',
          isMark: true,
        },
        {
          id: 4,
          searchCode: '大闸蟹',
          isMark: false,
        },
        {
          id: 5,
          searchCode: '电视',
          isMark: false,
        },
        {
          id: 6,
          searchCode: '洗发水',
          isMark: false,
        },
      ],
    }
  },
  props: {
    hotSearchList: {
      type: Array,
      default: function() {
        return [
          {
            id: 1,
            searchCode: '电动牙刷',
            isMark: false,
          },
          {
            id: 2,
            searchCode: '汾酒超品日',
            isMark: true,
          },
          {
            id: 3,
            searchCode: '九阳超品预定',
            isMark: true,
          },
          {
            id: 4,
            searchCode: '大闸蟹',
            isMark: false,
          },
          {
            id: 5,
            searchCode: '电视',
            isMark: false,
          },
          {
            id: 6,
            searchCode: '洗发水',
            isMark: false,
          },
          {
            id: 7,
            searchCode: '0元购买手机',
            isMark: true,
          },
          {
            id: 8,
            searchCode: '茅台',
            isMark: true,
          },
          {
            id: 9,
            searchCode: '笔记本',
            isMark: false,
          },
          {
            id: 10,
            searchCode: '电饭煲',
            isMark: false,
          },
          {
            id: 11,
            searchCode: '大米',
            isMark: false,
          },
          {
            id: 12,
            searchCode: '手表',
            isMark: false,
          },
        ]
      },
    },
  },
  mounted() {
    // console.log(this.hotSearchList)
  },
  methods: {
    onSearch() {
      this.$router.push('/searchResultList')
    },
    goback() {
      this.$router.go(-1)
    },
  },
}
</script>
<style lang="less" scoped>
@import '../../style/mixin.less';
// 头部搜索框start
.hot-search-header {
  padding-right: 0.213333rem;
  background-color: #fff;
  display: flex;
  // border-bottom: 1px solid #333;
  .hot-search-back {
    width: 2.133333rem;
    height: 2.133333rem;
    position: relative;
    &::before {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;

      display: inline-block;
      width: 0.597333rem;
      height: 0.597333rem;
      border: 1px solid #353d44;
      border-width: 1px 0 0 1px;
      // transform: rotate(-45deg);
      transform: translate(-50%, -50%) rotate(-45deg);
    }
  }
  .hot-search-block {
    flex: 1;
  }
}
/deep/.van-search {
  padding-left: 0;
}
/deep/.van-search__content {
  padding-left: 0;
}
// 头部搜索框end
// 热门搜索与历史记录start
.hot-search-key,
.hot-search-history {
  background-color: #fff;
  border-top: 1px solid #ccc;
  position: relative;
  z-index: 99;
  font-size: 0.682667rem;
  color: #333;
  overflow: hidden;
  > dl {
    overflow: hidden;
    > dt {
      color: #999;
      padding-left: 0.426667rem;
    }
    > dd {
      width: 14.933333rem;
      margin: 0 auto;
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      margin-top: 0.426667rem;
      margin-bottom: 0.426667rem;
      > span {
        background-color: #f2f2f2;
        display: inline-block;
        width: 4.693333rem;
        height: 1.28rem;
        margin-bottom: 0.426667rem;
        text-align: center;
        line-height: 1.28rem;
        font-size: 0.597333rem;
      }
    }
  }
}
.super-hot {
  color: #f60;
}
// 热门搜索end
</style>
